package com.codegeek.project.slope.service.impl;

import com.codegeek.common.utils.DateUtils;
import com.codegeek.project.slope.domain.SlopeCamera;
import com.codegeek.project.slope.mapper.SlopeCameraMapper;
import com.codegeek.project.slope.service.ISlopeCameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 摄像头Service业务层处理
 *
 * @author codegeek
 * @date 2020-02-17
 */
@Service
public class SlopeCameraServiceImpl implements ISlopeCameraService {
    @Autowired
    private SlopeCameraMapper slopeCameraMapper;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 查询摄像头
     *
     * @param cameraId 摄像头ID
     * @return 摄像头
     */
    @Override
    public SlopeCamera selectSlopeCameraById(Long cameraId) {
        return slopeCameraMapper.selectSlopeCameraById(cameraId);
    }

    /**
     * 查询摄像头列表
     *
     * @param slopeCamera 摄像头
     * @return 摄像头
     */
    @Override
    public List<SlopeCamera> selectSlopeCameraList(SlopeCamera slopeCamera) {
        return slopeCameraMapper.selectSlopeCameraList(slopeCamera);
    }

    /**
     * 新增摄像头
     *
     * @param slopeCamera 摄像头
     * @return 结果
     */
    @Override
    public int insertSlopeCamera(SlopeCamera slopeCamera) {
        slopeCamera.setCreateTime(DateUtils.getNowDate());
        return slopeCameraMapper.insertSlopeCamera(slopeCamera);
    }

    /**
     * 修改摄像头
     *
     * @param slopeCamera 摄像头
     * @return 结果
     */
    @Override
    public int updateSlopeCamera(SlopeCamera slopeCamera) {
        slopeCamera.setUpdateTime(DateUtils.getNowDate());
        return slopeCameraMapper.updateSlopeCamera(slopeCamera);
    }

    /**
     * 批量删除摄像头
     *
     * @param cameraIds 需要删除的摄像头ID
     * @return 结果
     */
    @Override
    public int deleteSlopeCameraByIds(Long[] cameraIds) {
        return slopeCameraMapper.deleteSlopeCameraByIds(cameraIds);
    }

    /**
     * 删除摄像头信息
     *
     * @param cameraId 摄像头ID
     * @return 结果
     */
    @Override
    public int deleteSlopeCameraById(Long cameraId) {
        return slopeCameraMapper.deleteSlopeCameraById(cameraId);
    }

    /**
     * 检查新增摄像头名称是否重复
     *
     * @param name
     * @return
     */
    @Override
    public List<Map<String, Object>> checkCameraName(String name) {
        StringBuilder sql = new StringBuilder("SELECT * FROM slope_device WHERE device_name = '" + name + "'");
        return jdbcTemplate.queryForList(sql.toString());
    }
}
